package com.dlc.commonlibrary.ble;

import com.dlc.commonlibrary.utils.LogPlus;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by John on 2017/7/27.
 */

public class RfidHelper {

        public static ArrayList<String> exportRFIDs(String text) {

            ArrayList<String> output = new ArrayList<>();
            text = text.replace(">A3","");
            int i = text.indexOf(BleConstant.API_STOP_Cache);
            text = text.substring(0,i);
            text = text+">";
          //  PrefUtil.getDefault().putString(Constants.LoginData.DATA,text).apply();
            Pattern pattern =  Pattern.compile("T[^T]+>");//Pattern.compile("T\\w{28}>");
            LogPlus.e("BLE", "mData:" + text);
            Matcher matcher = pattern.matcher(text);
            while (matcher.find()) {
                String str = matcher.group();
                if (str.length() > 14) {
                    str = str.substring(str.length() - 13, str.length() - 1);
                    output.add(str);
                }
            }
            //output = removeDuplicateWithOrder(output);

            return output;
    }


    public static List removeDuplicateWithOrder(List list) {
        Set set = new HashSet();
        ArrayList newList = new ArrayList();
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            Object element = iter.next();
            if (set.add(element))
                newList.add(element);
        }
        return newList;
    }




    //>p0>f13>Af>T3000EFCF115D444C00013B7B3994>T3000E2806811000000393B7B3873>T3000E2806811000000393B7B400F>T3000E2806811000000393B7B24D3>
    // T3000A8CC44B1ACEF00013B7B1DA5>T3000E2806811000000393B7B4335>T3000E2806811000000393B7B337B>T3000E2806811000000393B7B3E0F>
    // T3000E2806811000000393B7B571D>T3000E2806811000000393B7B3117>T3000E2806811000000393B7B3125>T3000E2806811000000393B7B407A>
    // T3000E2806811000000393B7B515CT>


    //[00013B7B3994, 00393B7B3873, 00393B7B400F, 00393B7B24D3, 00013B7B1DA5, 00393B7B4335, 00393B7B337B, 00393B7B3E0F,
    // 00393B7B571D, 00393B7B3117, 00393B7B3125, 00393B7B407A]



}
